﻿using System;
using System.Collections.Generic;
using System.Text;

namespace G3.State
{
    public struct Quad
    {
        public double x1;
        public double x2; // [ x1 x2 ]
        public double y1; // [ y1 y2 ]
        public double y2;

        public Quad(double x1, double x2, double y1, double y2)
        {
            this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2;
        }
    }

    public struct Pair
    {
        public double x; // [ x ]
        public double y; // [ y ]

        public Pair(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        static public Pair operator +(Pair p1, Pair p2)
        {
            return new Pair(p1.x + p2.x, p1.y + p2.y);
        }

        static public Pair operator -(Pair p1, Pair p2)
        {
            return new Pair(p1.x - p2.x, p1.y - p2.y);
        }

        static public Pair operator -(Pair p, double d)
        {
            return new Pair(p.x - d, p.y - d);
        }

        static public Pair operator *(double scalar, Pair p)
        {
            return new Pair(scalar * p.x, scalar * p.y);
        }

        static public Pair operator *(Quad matrix, Pair vector)
        {
            return new Pair(matrix.x1 * vector.x + matrix.x2 * vector.y,
                            matrix.y1 * vector.x + matrix.y2 * vector.y);
        }

        static public double operator *(Pair p1, Pair p2)
        {
            return p1.x * p2.x + p1.y * p2.y;
        }

        public double Abs()
        {
            return Math.Sqrt(x * x + y * y);
        }
    }
}
